package com.xuan.juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/*
* 线程就是一个单独的资源类，没有任何附属的操作
*
*
* */
public class Test2 {
    public static void main(String[] args) {
        // 获取cpu的核数
        // cpu 密集型 io密集型
        System.out.println(Runtime.getRuntime().availableProcessors());

        Ticket ticket = new Ticket();
        new Thread(() ->{ticket.sale();},"A").start();


    }
}

//
/*
* lock 三部曲
* 1 new reentrantlock
* 2 lock.lock
* 3 lock.unlock
* */
class Ticket2{

    private int num = 10;

    Lock lock =new ReentrantLock();

    // 本质 锁
    public void sale(){
        lock.lock();
        lock.tryLock();
        try {
            if(num > 0){
            }
        }catch (Exception e){

        }finally {
            lock.unlock();
        }

    }

}